//
//  FourthViewController.m
//  HomeFurnishing
//
//  Created by dllo on 16/4/7.
//  Copyright © 2016年 YMing. All rights reserved.
//

#import "FourthViewController.h"
#import "CaseBaseModel.h"
#import "FourthVCTableViewCell.h"
#import "DetailFourthVC.h"
@interface FourthViewController ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, retain)UITableView *tableV;
@property(nonatomic, retain)NSMutableArray *dataArr;
@property(nonatomic, retain)NSMutableArray *titleArr;
@property(nonatomic, retain)NSMutableArray *widthArr;
@property(nonatomic, retain)NSMutableArray *heightArr;
@end

@implementation FourthViewController
-(NSString *)segmentTitle
{
    return [NSString stringWithFormat:@"%@ 分享",self.num];
}
-(UIScrollView *)streachScrollView
{
    return self.tableV;
}

-(void)dealloc
{
    [_tableV release];
    [_num release];
    [_dataArr release];
    [_titleArr release];
    [_widthArr release];
    [_heightArr release];
    [_name release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.dataArr = [NSMutableArray array];
    self.titleArr = [NSMutableArray array];
    self.widthArr = [NSMutableArray array];
    self.heightArr = [NSMutableArray array];
    self.tableV = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    self.tableV.rowHeight = 210;
    [self.view addSubview:self.tableV];
    [_tableV release];
    [self.tableV registerClass:[FourthVCTableViewCell class] forCellReuseIdentifier:@"FourthTableVCCell"];
    [self dataHandle];

}
-(void)dataHandle
{
    NSString *str = [NSString stringWithFormat:@"http://api.guju.com.cn/v2/user/%@/projects?start=0&count=10&user=木木",self.name];
    NSString *newStr = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
    [NetworkHandle GetDataWithURL:newStr dic:nil success:^(id responseObject) {
//        self.dataArr = [CaseBaseModel transformWithArray:responseObject[@"projects"][@"photo"]];
        self.widthArr = responseObject[@"projects"];
        for (NSDictionary *dic in responseObject[@"projects"]) {
            for (NSDictionary *dicc in dic[@"photos"]) {
                [self.dataArr addObject:dicc[@"id"]];
                [self.titleArr addObject:dicc[@"title"]];
            }
        }
        [self.tableV reloadData];
    } filed:^(NSError *error) {
        
    }];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    FourthVCTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FourthTableVCCell" forIndexPath:indexPath];
//    CaseBaseModel *m = self.dataArr[indexPath.row];
    NSString *str = [NSString stringWithFormat:@"http://gooju.cn/dimages/%@_0_w750_h398_m0.jpg",self.dataArr[indexPath.row]];
    [cell.imgView sd_setImageWithURL:[NSURL URLWithString:str]];
    cell.title.text = self.titleArr[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailFourthVC *VC = [[DetailFourthVC alloc] init];
    VC.widthArr = self.widthArr[indexPath.row][@"photos"];
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC animated:YES];
    [VC release];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
